package com.atguigu.mybatis.util;

import com.atguigu.mybatis.mapper.ParameterMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.swing.plaf.nimbus.State;
import java.io.IOException;
import java.io.InputStream;

/**
 * @date: 2022/3/3 10:18
 * @description:
 */
public class SqlSessionUtil {


    public static SqlSession getSqlSession(){
        String resource ="mybatis-config.xml";
        SqlSession sqlSession = null;
        try {
            InputStream is = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
            sqlSession = sqlSessionFactory.openSession(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sqlSession;
    }
}
